import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

class DynamicArray {
    //动态数组实现
    private int size = 0;   //数组大小
    private int capacity = 10;  //实际容量
    private int[] array = new int[capacity];

    public void addLast(int element){
        //容量检查
        extracted();

        add(size,element);
    }

    public void add(int index, int element){
        //容量检查
        extracted();

        if(index >= 0 && index < capacity){
            System.arraycopy(array,index,array,index+1,size-index);
        }
        array[index] = element;
        size++;
    }
       //扩容
    private void extracted() {
        if (size == capacity){
            capacity += capacity>>1;
            int[] newArray = new int[capacity];
            System.arraycopy(array,0,newArray,0,size);
            array = newArray;
        }
    }

    public int remove(int index){

         int ret = array[index];
        if (index < size - 1){
            System.arraycopy(array,index+1,array,index,size-index);
        }

        size--;
        return ret;
     }

    public int getSize(){
        return size;
    }

    public int getArray(int num){
        return array[num];
    }
}

public class demo1 {
    public static void main(String[] args) {
        DynamicArray arr = new DynamicArray();
        arr.addLast(1);
        arr.addLast(2);
        arr.addLast(3);
        arr.addLast(4);
        arr.addLast(5);
        arr.addLast(6);
        arr.addLast(7);
        arr.addLast(8);
        arr.addLast(9);
        arr.addLast(1);
        arr.addLast(2);
        arr.addLast(3);
        arr.addLast(4);

        arr.add(1,9);

        for (int i = 0; i < arr.getSize(); i++) {
            System.out.print(arr.getArray(i)+" ");
        }
        System.out.println();

        arr.remove(1);
        for (int i = 0; i < arr.getSize(); i++) {
            System.out.print(arr.getArray(i)+" ");

        }

    }
}
